package org.code;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 
 * @author zhujunbing
 * @date   2019年2月12日
 */
public class Lt173 {

}


/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class BSTIterator {

	
	
    private Queue<Integer> queue;

	public BSTIterator(TreeNode root) {
		queue = new LinkedList<>();
        setQueue(root);
    }
    
    private void setQueue(TreeNode root) {
    	
    	if(root==null) {
    		return;
    	}
    	
    	setQueue(root.left);
    	queue.add(root.val);
    	setQueue(root.right);
    	
	}

	/** @return the next smallest number */
    public int next() {
		return queue.isEmpty()?-1:queue.poll();
    }
    
    /** @return whether we have a next smallest number */
    public boolean hasNext() {
		return !queue.isEmpty();
    }
}

/**
 * Your BSTIterator object will be instantiated and called as such:
 * BSTIterator obj = new BSTIterator(root);
 * int param_1 = obj.next();
 * boolean param_2 = obj.hasNext();
 */


 class TreeNode {
	     int val;
	     TreeNode left;
	     TreeNode right;
	     TreeNode(int x) { val = x; }
	     }